﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;
using Carmenta.SpatialAce.Interop.SpatialAce;
using CEPowerPack;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // Collection support (construction from enumerations and tolist extension methods)
            Points polygon = Factory.CreatePoints(new [] { new Point { X = 0, Y = 0 }, new Point { X = 10, Y = 40 }, new Point { X = 40, Y = 10 } });
            IEnumerable<Point> zeroX = polygon.ToList().Where(p => p.X == 0);

            // Factory methods
            var wgs84 = Factory.GetRefSystem("WGS84lola");
            var myDs = Factory.CreateInternalStore(Name: "", RefSys: wgs84) as DataSet;
            var geoLine = Factory.CreateGeoLine(DataSet: myDs, Points: polygon);
            var readOp = Factory.CreateReadOp(Name: "", DataSet: myDs) as Operator;
            var lineVis = Factory.CreateLineVis(Name: "", Color: Factory.CreateDirectColorAttributeVariable(0, 128, 128)) as Visualizer;
            var visList = Factory.CreateVisualizers(new[] { lineVis });
            var renderOp = Factory.CreateRenderOp(Name: "", Input: readOp, VisList: visList) as Operator;
            var layer = Factory.CreateOrdinaryLayer(Name: "", Operators: Factory.CreateOperators(new [] { renderOp })) as Layer;
            var drawable = Factory.CreateWindow(Name: "", Width:400, Height:400, X:10, Y:10) as Drawable;
            var geoRect = new Rect { Xmin = -10, Ymin = -10, Xmax = 100, Ymax = 100 };
            var view = Factory.CreateView(Name: "", Drawable: drawable, Layers: Factory.CreateLayers(new [] { layer }), RefSys:wgs84, GeoRect: geoRect);            

            // Test
            view.Update();
            Console.ReadLine();
        }
    }
}
